package bean;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Date;

import data.DataConn;

import bean.ContentBean;

public class showContent {

	public ArrayList viewContent(int id) {
		ArrayList content = new ArrayList();
		String sql = "select * from content where id="+id;
		try {
			DataConn dataconn = new DataConn();
			Connection conn = dataconn.getConn("root", "root", "test");
			Statement statement = dataconn.getStatement(conn);
			ResultSet rs = dataconn.getResultSet(statement, sql);
			
			while(rs.next()) {
				ContentBean art = new ContentBean();
				art.setTitle(rs.getString("title"));
				art.setContent(rs.getString("content"));
				art.setUser(rs.getString("puser"));
				art.setPosttime(dataconn.toStrChnYmdHms(rs.getTimestamp("posttime")));
				art.setReplaytxt(rs.getString("replay_txt"));
				content.add(art);
			}
			conn.close();
			statement.executeUpdate("update `content` set HitsNum = HitsNum +1 where id="+id);
			statement.close();
			rs.close();
		}catch(SQLException ex) {
			ex.printStackTrace();
		}finally{
			//conn.close();
			
		}
		return content;
	}
}
